import React from 'react';
import Taro from '@tarojs/taro';
import {View, Image, Block} from '@tarojs/components'
import {AtIcon} from 'taro-ui'
import {SubscriptionType} from "../../utils/server.interface";
import './subscription.scss'

const Subscription: React.FC<{ data: SubscriptionType | false; position?: string }> = (props) => {
  return (
    <Block>
      {props.data && process.env.TARO_ENV !== 'tt' && <Block>
        {props.data.type ? <View className='subscription-img' onClick={() => Taro.navigateTo({
            url: '/main/webview/index?url=' + props.data.url
          })}
        >
            <Image src={props.data.img} mode='widthFix' />
          </View>
          :
          <View className={`${props.position + 'position'} subscription`} onClick={() => Taro.navigateTo({
            url: '/main/webview/index?url=' + props.data.url
          })}
          >
            <Image src={props.data.img} mode='widthFix' />
            <View className='subscription_tip'>
              <View className='tip_title'>{props.data.title}</View>
              <View className='tip_sub_title'>{props.data.sub_title}</View>
            </View>
            <AtIcon value='chevron-right' size='30' color='#ddd' />
          </View>
        }
      </Block>}
    </Block>
  )
}
Subscription.defaultProps = {
  data: false
}
export default Subscription
